home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / contrib / bstfiles.zoo / btxbst.doc < prev    next >
Text File  |  1988-03-23  |  67KB  |  2,529 lines

  1. % BibTeX `plain' family
  2.     % version 0.99b for BibTeX versions 0.99a or later, LaTeX version 2.09.
  3.     % Copyright (C) 1985, all rights reserved.
  4.     % Copying of this file is authorized only if either
  5.     % (1) you make absolutely no changes to your copy, including name, or
  6.     % (2) if you do make changes, you name it something other than
  7.     % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
  8.     % This restriction helps ensure that all standard styles are identical.
  9.     % The file btxbst.doc has the documentation for this style.
  10. % Please notify Oren Patashnik (PATASHNIK@SCORE.STANFORD.EDU) of any bugs in
  11. % these standard styles or in this documentation file.
  12. %
  13. % This is file btxbxt.doc; it helps document bibliography styles,
  14. % and is also a template file that you can use to make
  15. % several different style files, if you have access to a C preprocessor.
  16. % For example, the standard styles were made by doing something like
  17. %    cpp -P -DPLAIN btxbst.doc plain.txt
  18. %    cpp -P -DUNSRT btxbst.doc unsrt.txt
  19. %    cpp -P -DALPHA btxbst.doc alpha.txt
  20. %    cpp -P -DABBRV btxbst.doc abbrv.txt
  21. % and then renaming after removing unwanted comments and blank lines.
  22. % If you don't have access,
  23. % you can edit this file by hand to imitate the preprocessor,
  24. % with the following explanation of the C preprocessor constructs used here.
  25. %
  26. % The output of the preprocessor is the same as the input, except that certain
  27. % lines will be excluded (and some blank lines will be added).  The sequence
  28. %    #if VAR
  29. %        lines to be included when VAR is not zero
  30. %    #else
  31. %        lines to be included when VAR is zero
  32. %    #endif
  33. % (with the #-signs appearing in column 1) means that one set or the other of
  34. % the lines are to be included depending on the value of VAR.
  35. % The #else part is optional.  Comments can be added after #else and #endif.
  36. % Variables can be set by
  37. %    #define VAR value
  38. % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
  39. % to see if it has none.
  40. % Another #if form used in this file is #if !VAR, which includes the lines
  41. % after the #if only if VAR is zero.
  42. %
  43. % Convention: Use all uppercase identifiers for these preprocessor variables
  44. % so you can spot them easily
  45. %
  46. % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
  47. % or ABBRV (though PLAIN will be used by default if none is given),
  48. % and the following lines will set various boolean variables to control the
  49. % various lines that are chosen from the rest of the file.
  50. % Each boolean variable should be set true (1) or false (0) in each style.
  51. % Here are the current variables, and their meanings:
  52. %    LAB_ALPH:    an alphabetic label is used (if false then a numeric
  53. %                label is used)
  54. %    SORTED:        the entries should be sorted by label (if nonnumeric)
  55. %                and other info, like authors (if false, then
  56. %                entries remain in order of occurrence)
  57. %    NAME_FULL:    the authors, editors, etc., get the full names as
  58. %                given in the bibliography file (if false, the first
  59. %                names become initials)
  60. %    ATIT_LOWER:    titles of non-"books" (e.g., articles) should be
  61. %                converted to lower-case, except the first letter or
  62. %                first letter after a colon
  63. %                (if false then they appear as in the database)
  64. %    MONTH_FULL:    months are spelled out in full (if false, then
  65. %                they're abbreviated)
  66. %    JOUR_FULL:    macro journal names are spelled out in full
  67. %                (if false then they are abbreviated, currently
  68. %                as they appear in ACM publications)
  69. #ifndef UNSRT
  70. #   ifndef ALPHA
  71. #    ifndef ABBRV
  72. #        define PLAIN 1
  73. #    endif
  74. #   endif
  75. #endif
  76. #ifdef PLAIN
  77. % plain style (sorted numbers)
  78. #   define LAB_ALPH 0
  79. #   define SORTED 1
  80. #   define NAME_FULL 1
  81. #   define ATIT_LOWER 1
  82. #   define MONTH_FULL 1
  83. #   define JOUR_FULL 1
  84. #endif
  85. #ifdef UNSRT
  86. % unsrt style (unsorted numbers)
  87. #   define LAB_ALPH 0
  88. #   define SORTED 0
  89. #   define NAME_FULL 1
  90. #   define ATIT_LOWER 1
  91. #   define MONTH_FULL 1
  92. #   define JOUR_FULL 1
  93. #endif
  94. #ifdef ALPHA
  95. % alpha style (sorted short alphabetics)
  96. #   define LAB_ALPH 1
  97. #   define SORTED 1
  98. #   define NAME_FULL 1
  99. #   define ATIT_LOWER 1
  100. #   define MONTH_FULL 1
  101. #   define JOUR_FULL 1
  102. #endif
  103. #ifdef ABBRV
  104. % abbrv style (sorted numbers, with abbreviations)
  105. #   define LAB_ALPH 0
  106. #   define SORTED 1
  107. #   define NAME_FULL 0
  108. #   define ATIT_LOWER 1
  109. #   define MONTH_FULL 0
  110. #   define JOUR_FULL 0
  111. #endif
  112. %
  113. %   Entry formatting: Similar to that recommended by Mary-Claire van Leunen
  114. %    in "A Handbook for Scholars".  Book-like titles are italicized
  115. %    (emphasized) and non-book titles are converted to sentence
  116. %    capitilization (and not enclosed in quotes).
  117. %    This file outputs a \newblock between major blocks of an entry
  118. %    (the name \newblock is analogous to the names \newline and \newpage)
  119. %    so that the user can obtain an "open" format, which has a line break
  120. %    before each block and lines after the first are indented within blocks,
  121. %    by giving the optional \documentstyle argument `openbib';
  122. %    The default is the "closed" format---blocks runs together.
  123. %
  124. %   Citation alphabetic label format:
  125. %        [Knu73] for single author (or editor or key)
  126. %        [AHU83] (first letters of last names) for multiple authors
  127. %
  128. %   Citation label numberic format:
  129. %        [number]
  130. %
  131. %   Reference list ordering for sorted, alphabetic lables:
  132. %        alphabetical by citation label, then by author(s) or whatever
  133. %        passes for author in the absence of one, then by year,
  134. %        then title
  135. %
  136. %   Reference list ordering for sorted, numeric lables:
  137. %        alphabetical by author(s) or whatever passes
  138. %        for author in the absence of one, then by year, then title
  139. %
  140. %   Reference list ordering for unsorted:
  141. %        by the order cited in the text
  142. %
  143. %   History
  144. %   12/16/84    (HWT)    Original `plain' version, by Howard Trickey.
  145. %   12/23/84    (LL)    Some comments made by Leslie Lamport.
  146. %    2/16/85    (OP)    Changes based on LL's comments, Oren Patashnik.
  147. %    2/17/85    (HWT)    Template file and other standard styles made.
  148. %    3/28/85    (OP)    First release, version 0.98b for BibTeX 0.98f.
  149. %    5/ 9/85    (OP)    Version 0.98c for BibTeX 0.98i:
  150. %            fixed Theoretical Computer Science macro name;
  151. %            fixed the format.vol.num.pages function.
  152. %    1/24/88    (OP)    Version 0.99a for BibTeX 0.99a, main changes:
  153. %            assignment operator (:=) arguments reversed;
  154. %            the preamble$ function outputs the database PREAMBLE;
  155. %            entry.max$ and global.max$ (built-in) variables replace
  156. %            entry.string.max and global.string.max functions;
  157. %            alphabetizing by year then title, not just title;
  158. %            many unnecessary ties removed; \it ==> \em;
  159. %            the `alpha' style uses a superscripted `+' instead of a
  160. %            `*' for unnamed names in constructing the label;
  161. %            the `abbrv' style now uses "Mar." and "Sept.";
  162. %            the functions calc.label and presort now look at just
  163. %            the fields they're supposed to;
  164. %            BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
  165. %            INBOOK and INCOLLECTION take an optional type (e.g.
  166. %            type = "Section"), overriding the default "chapter";
  167. %            BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
  168. %            either volume or number, not just volume;
  169. %            INCOLLECTION now allows an edition and series field;
  170. %            PROCEEDINGS and INPROCEEDINGS now use the address field
  171. %            to tell where a conference was held;
  172. %            INPROCEEDINGS and PROCEEDINGS now allow either volume
  173. %            or number, and also a series field;
  174. %            MASTERSTHESIS and PHDTHESIS accept types other than
  175. %            "Master's thesis" and "PhD thesis";
  176. %            UNPUBLISHED now outputs, in one block, note then date;
  177. %            MANUAL now prints out the organization in
  178. %            the first block if the author field is empty;
  179. %            MISC can't be empty---it requires some optional field.
  180. %    3/23/88    (OP)    Version 0.99b for BibTeX 0.99c---changed the three
  181. %            erroneous occurrences of `cite ' to `cite$ '; this
  182. %            change didn't affect the four standard styles, so the
  183. %            0.99a versions of those styles are still current.
  184. %
  185. % The ENTRY declaration
  186. %   Like Scribe's (according to pages 231-2 of the April '84 edition),
  187. %   but no fullauthor or editors fields because BibTeX does name handling.
  188. %   The annote field is commented out here because this family doesn't
  189. %   include an annotated bibliography style.  And in addition to the fields
  190. %   listed here, BibTeX has a built-in crossref field, explained later.
  191.  
  192. ENTRY
  193. % Fields:
  194.   { address
  195. %        Usually the address of a publisher or other type of organization.
  196. %        Put information in this field only if it helps the reader find the
  197. %        thing---for example you should omit the address of a major
  198. %        publisher entirely.  For a PROCEEDINGS or an INPROCEEDINGS,
  199. %        however, it's the address of the conference; for those two entry
  200. %        types, include the publisher's or organization's address, if
  201. %        necessary, in the publisher or organization field.
  202. %    annote
  203. %        Long annotation---for annotated bibliographies (begins sentence).
  204.     author
  205. %        Name(s) of author(s), in BibTeX name format.
  206.     booktitle
  207. %        Book title when the thing being referenced isn't the whole book.
  208. %        For book entries, the title field should be used instead.
  209.     chapter
  210. %        Chapter (or section or whatever) number.
  211.     edition
  212. %        Edition of a book---should be an ordinal (e.g., "Second").
  213.     editor
  214. %        Name(s) of editor(s), in BibTeX name format.
  215. %        If there is also an author field, then the editor field should be
  216. %        for the book or collection that the work appears in.
  217.     howpublished
  218. %         How something strange has been published (begins sentence).
  219.     institution
  220. %        Sponsoring institution of a technical report.
  221.     journal
  222. %        Journal name (macros are provided for many).
  223.     key
  224. %        Alphabetizing, labeling, and cross-referencing key
  225. %        (needed when an entry has no author or editor).
  226.     month
  227. %        Month (macros are provided).
  228.     note
  229. %        To help the reader find a reference (begins sentence).
  230.     number
  231. %        Number of a journal or technical report, or of a work in a series.
  232.     organization
  233. %        Organization sponsoring a conference (or publishing a manual); if
  234. %        the editor (or author) is empty, and if the organization produces
  235. %        an awkward label or cross reference, you should put appropriately
  236. %        condensed organization information in the key field as well.
  237.     pages
  238. %        Page number or numbers (use `--' to separate a range, use `+'
  239. %        to indicate pages following that don't form a simple range).
  240.     publisher
  241. %        Publisher name.
  242.     school
  243. %        School name (for theses).
  244.     series
  245. %        The name of a series or set of books.
  246. %        An individual book will will also have it's own title.
  247.     title
  248. %        The title of the thing you're referred to.
  249.     type
  250. %        Type of a Techreport (e.g., "Research Note") to be used instead of
  251. %        the default "Technical Report"; or, similarly, the type of a
  252. %        thesis; or of a part of a book.
  253.     volume
  254. %        The volume number of a journal or multivolume work.
  255.     year
  256. %        The year should contain only numerals (technically, it should end
  257. %        with four numerals, after purification; doesn't a begin sentence).
  258.   }
  259. % There are no integer entry variables
  260.   {}
  261. % These string entry variables are used to form the citation label.
  262. % In a storage pinch, sort.label can be easily computed on the fly.
  263. #if LAB_ALPH
  264. #if SORTED
  265.   { label extra.label sort.label }
  266. #else !SORTED
  267. % It doesn't seem like a good idea to use an order-of-citation
  268. % reference list when using alphabetic labels, but when this happens
  269. % we do things a little differently
  270.   { label }
  271. #endif SORTED
  272. #else !LAB_ALPH
  273.   { label }
  274. #endif LAB_ALPH
  275.  
  276. % Each entry function starts by calling output.bibitem, to write the
  277. % \bibitem and its arguments to the .BBL file.  Then the various fields
  278. % are formatted and printed by output or output.check.  Those functions
  279. % handle the writing of separators (commas, periods, \newblock's),
  280. % taking care not to do so when they are passed a null string.
  281. % Finally, fin.entry is called to add the final period and finish the
  282. % entry.
  283. %
  284. % A bibliographic reference is formatted into a number of `blocks':
  285. % in the open format, a block begins on a new line and subsequent
  286. % lines of the block are indented.  A block may contain more than
  287. % one sentence (well, not a grammatical sentence, but something to
  288. % be ended with a sentence ending period).  The entry functions should
  289. % call new.block whenever a block other than the first is about to be
  290. % started.  They should call new.sentence whenever a new sentence is
  291. % to be started.  The output functions will ensure that if two
  292. % new.sentence's occur without any non-null string being output between
  293. % them then there won't be two periods output.  Similarly for two
  294. % successive new.block's.
  295. %
  296. % The output routines don't write their argument immediately.
  297. % Instead, by convention, that argument is saved on the stack to be
  298. % output next time (when we'll know what separator needs to come
  299. % after it).  Meanwhile, the output routine has to pop the pending
  300. % output off the stack, append any needed separator, and write it.
  301. %
  302. % To tell which separator is needed, we maintain an output.state.
  303. % It will be one of these values:
  304. %    before.all        just after the \bibitem
  305. %    mid.sentence        in the middle of a sentence: comma needed
  306. %                    if more sentence is output
  307. %    after.sentence        just after a sentence: period needed
  308. %    after.block        just after a block (and sentence):
  309. %                    period and \newblock needed.
  310. % Note: These styles don't use after.sentence
  311. %
  312. % VAR: output.state : INTEGER        -- state variable for output
  313. %
  314. % The output.nonnull function saves its argument (assumed to be nonnull)
  315. % on the stack, and writes the old saved value followed by any needed
  316. % separator.  The ordering of the tests is decreasing frequency of
  317. % occurrence.
  318. %
  319. % output.nonnull(s) ==
  320. %  BEGIN
  321. %    s := argument on stack
  322. %    if output.state = mid.sentence then
  323. %        write$(pop() * ", ")
  324. %          -- "pop" isn't a function: just use stack top
  325. %    else
  326. %        if output.state = after.block then
  327. %        write$(add.period$(pop()))
  328. %        newline$
  329. %        write$("\newblock ")
  330. %        else
  331. %        if output.state = before.all then
  332. %            write$(pop())
  333. %        else        -- output.state should be after.sentence
  334. %            write$(add.period$(pop()) * " ")
  335. %        fi
  336. %        fi
  337. %        output.state := mid.sentence
  338. %    fi
  339. %    push s on stack
  340. %  END
  341. %
  342. % The output function calls output.nonnull if its argument is non-empty;
  343. % its argument may be a missing field (thus, not necessarily a string)
  344. %
  345. % output(s) ==
  346. %  BEGIN
  347. %    if not empty$(s) then output.nonnull(s)
  348. %    fi
  349. %  END
  350. %
  351. % The output.check function is the same as the output function except that, if
  352. % necessary, output.check warns the user that the t field shouldn't be empty
  353. % (this is because it probably won't be a good reference without the field;
  354. % the entry functions try to make the formatting look reasonable even when
  355. % such fields are empty).
  356. %
  357. % output.check(s,t) ==
  358. %  BEGIN
  359. %    if empty$(s) then
  360. %        warning$("empty " * t * " in " * cite$)
  361. %    else output.nonnull(s)
  362. %    fi
  363. %  END
  364. %
  365. % The output.bibitem function writes the \bibitem for the current entry
  366. % (the label should already have been set up), and sets up the separator
  367. % state for the output functions.  And, it leaves a string on the stack
  368. % as per the output convention.
  369. %
  370. % output.bibitem ==
  371. %  BEGIN
  372. %    newline$
  373. %    write$("\bibitem[")    % for alphabetic labels,
  374. %    write$(label)        % these three lines
  375. %    write$("]{")        % are used
  376. %    write$("\bibitem{")        % this line for numeric labels
  377. %    write$(cite$)
  378. %    write$("}")
  379. %    push "" on stack
  380. %    output.state := before.all
  381. %  END
  382. %
  383. % The fin.entry function finishes off an entry by adding a period to the
  384. % string remaining on the stack.  If the state is still before.all
  385. % then nothing was produced for this entry, so the result will look bad,
  386. % but the user deserves it. (We don't omit the whole entry because the
  387. % entry was cited, and a bibitem is needed to define the citation label.)
  388. %
  389. % fin.entry ==
  390. %  BEGIN
  391. %    write$(add.period$(pop()))
  392. %    newline$
  393. %  END
  394. %
  395. % The new.block function prepares for a new block to be output, and
  396. % new.sentence prepares for a new sentence.
  397. %
  398. % new.block ==
  399. %  BEGIN
  400. %    if output.state <> before.all then
  401. %        output.state := after.block
  402. %    fi
  403. %  END
  404. %
  405. % new.sentence ==
  406. %  BEGIN
  407. %    if output.state <> after.block then
  408. %        if output.state <> before.all then
  409. %        output.state :=  after.sentence
  410. %        fi
  411. %    fi
  412. %  END
  413. %
  414.  
  415. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  416.  
  417. FUNCTION {init.state.consts}
  418. { #0 'before.all :=
  419.   #1 'mid.sentence :=
  420.   #2 'after.sentence :=
  421.   #3 'after.block :=
  422. }
  423.  
  424. % the variables s and t are temporary string holders
  425.  
  426. STRINGS { s t }
  427.  
  428. FUNCTION {output.nonnull}
  429. { 's :=
  430.   output.state mid.sentence =
  431.     { ", " * write$ }
  432.     { output.state after.block =
  433.     { add.period$ write$
  434.       newline$
  435.       "\newblock " write$
  436.     }
  437.     { output.state before.all =
  438.         'write$
  439.         { add.period$ " " * write$ }
  440.       if$
  441.     }
  442.       if$
  443.       mid.sentence 'output.state :=
  444.     }
  445.   if$
  446.   s
  447. }
  448.  
  449. FUNCTION {output}
  450. { duplicate$ empty$
  451.     'pop$
  452.     'output.nonnull
  453.   if$
  454. }
  455.  
  456. FUNCTION {output.check}
  457. { 't :=
  458.   duplicate$ empty$
  459.     { pop$ "empty " t * " in " * cite$ * warning$ }
  460.     'output.nonnull
  461.   if$
  462. }
  463.  
  464. FUNCTION {output.bibitem}
  465. { newline$
  466. #if LAB_ALPH
  467.   "\bibitem[" write$
  468.   label write$
  469.   "]{" write$
  470. #else
  471.   "\bibitem{" write$
  472. #endif LAB_ALPH
  473.   cite$ write$
  474.   "}" write$
  475.   newline$
  476.   ""
  477.   before.all 'output.state :=
  478. }
  479.  
  480. % This function finishes all entries.
  481.  
  482. FUNCTION {fin.entry}
  483. { add.period$
  484.   write$
  485.   newline$
  486. }
  487.  
  488. FUNCTION {new.block}
  489. { output.state before.all =
  490.     'skip$
  491.     { after.block 'output.state := }
  492.   if$
  493. }
  494.  
  495. FUNCTION {new.sentence}
  496. { output.state after.block =
  497.     'skip$
  498.     { output.state before.all =
  499.     'skip$
  500.     { after.sentence 'output.state := }
  501.       if$
  502.     }
  503.   if$
  504. }
  505.  
  506. % These three functions pop one or two (integer) arguments from the stack
  507. % and push a single one, either 0 or 1.
  508. % The 'skip$ in the `and' and `or' functions are used because
  509. % the corresponding if$ would be idempotent
  510.  
  511. FUNCTION {not}
  512. {   { #0 }
  513.     { #1 }
  514.   if$
  515. }
  516.  
  517. FUNCTION {and}
  518. {   'skip$
  519.     { pop$ #0 }
  520.   if$
  521. }
  522.  
  523. FUNCTION {or}
  524. {   { pop$ #1 }
  525.     'skip$
  526.   if$
  527. }
  528.  
  529. % Sometimes we begin a new block only if the block will be big enough.  The
  530. % new.block.checka function issues a new.block if its argument is nonempty;
  531. % new.block.checkb does the same if either of its TWO arguments is nonempty.
  532.  
  533. FUNCTION {new.block.checka}
  534. { empty$
  535.     'skip$
  536.     'new.block
  537.   if$
  538. }
  539.  
  540. FUNCTION {new.block.checkb}
  541. { empty$
  542.   swap$ empty$
  543.   and
  544.     'skip$
  545.     'new.block
  546.   if$
  547. }
  548.  
  549. % The new.sentence.check functions are analogous.
  550.  
  551. FUNCTION {new.sentence.checka}
  552. { empty$
  553.     'skip$
  554.     'new.sentence
  555.   if$
  556. }
  557.  
  558. FUNCTION {new.sentence.checkb}
  559. { empty$
  560.   swap$ empty$
  561.   and
  562.     'skip$
  563.     'new.sentence
  564.   if$
  565. }
  566.  
  567. % Here are some functions for formatting chunks of an entry.
  568. % By convention they either produce a string that can be followed by
  569. % a comma or period (using add.period$, so it is OK to end in a period),
  570. % or they produce the null string.
  571. %
  572. % A useful utility is the field.or.null function, which checks if the
  573. % argument is the result of pushing a `missing' field (one for which no
  574. % assignment was made when the current entry was read in from the database)
  575. % or the result of pushing a string having no non-white-space characters.
  576. % It returns the null string if so, otherwise it returns the field string.
  577. % Its main (but not only) purpose is to guarantee that what's left on the
  578. % stack is a string rather than a missing field.
  579. %
  580. % field.or.null(s) ==
  581. %  BEGIN
  582. %    if empty$(s) then return ""
  583. %    else return s
  584. %  END
  585. %
  586. % Another helper function is emphasize, which returns the argument emphazised,
  587. % if that is non-empty, otherwise it returns the null string.  Italic
  588. % corrections aren't used, so this function should be used when punctation
  589. % will follow the result.
  590. %
  591. % emphasize(s) ==
  592. %  BEGIN
  593. %    if empty$(s) then return ""
  594. %    else return "{\em " * s * "}"
  595. %
  596. % The format.names function formats the argument (which should be in
  597. % BibTeX name format) into "First Von Last, Junior", separated by commas
  598. % and with an "and" before the last (but ending with "et~al." if the last
  599. % of multiple authors is "others").  This function's argument should always
  600. % contain at least one name.
  601. %
  602. % VAR: nameptr, namesleft, numnames: INTEGER
  603. % pseudoVAR: nameresult: STRING        (it's what's accumulated on the stack)
  604. %
  605. % format.names(s) ==
  606. %  BEGIN
  607. %    nameptr := 1
  608. %    numnames := num.names$(s)
  609. %    namesleft := numnames
  610. %    while namesleft > 0
  611. %      do
  612. %                % for full names:
  613. %        t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
  614. %                % for abbreviated first names:
  615. %        t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
  616. %        if nameptr > 1 then
  617. %        if namesleft > 1 then nameresult := nameresult * ", " * t
  618. %        else if numnames > 2
  619. %               then nameresult := nameresult * ","
  620. %             fi
  621. %             if t = "others"
  622. %               then nameresult := nameresult * " et~al."
  623. %               else nameresult := nameresult * " and " * t
  624. %             fi
  625. %        fi
  626. %        else nameresult := t
  627. %        fi
  628. %        nameptr := nameptr + 1
  629. %        namesleft := namesleft - 1
  630. %      od
  631. %    return nameresult
  632. %  END
  633. %
  634. % The format.authors function returns the result of format.names(author)
  635. % if the author is present, or else it returns the null string
  636. %
  637. % format.authors ==
  638. %  BEGIN
  639. %    if empty$(author) then return ""
  640. %    else return format.names(author)
  641. %    fi
  642. %  END
  643. %
  644. % Format.editors is like format.authors, but it uses the editor field,
  645. % and appends ", editor" or ", editors"
  646. %
  647. % format.editors ==
  648. %  BEGIN
  649. %    if empty$(editor) then return ""
  650. %    else
  651. %        if num.names$(editor) > 1 then
  652. %        return format.names(editor) * ", editors"
  653. %        else
  654. %        return format.names(editor) * ", editor"
  655. %        fi
  656. %    fi
  657. %  END
  658. %
  659. % Other formatting functions are similar, so no "comment version" will be
  660. % given for them.
  661. %
  662. % The `pop$' in this function gets rid of the duplicate `empty' value and
  663. % the `skip$' returns the duplicate field value
  664.  
  665. FUNCTION {field.or.null}
  666. { duplicate$ empty$
  667.     { pop$ "" }
  668.     'skip$
  669.   if$
  670. }
  671.  
  672. FUNCTION {emphasize}
  673. { duplicate$ empty$
  674.     { pop$ "" }
  675.     { "{\em " swap$ * "}" * }
  676.   if$
  677. }
  678.  
  679. INTEGERS { nameptr namesleft numnames }
  680.  
  681. FUNCTION {format.names}
  682. { 's :=
  683.   #1 'nameptr :=
  684.   s num.names$ 'numnames :=
  685.   numnames 'namesleft :=
  686.     { namesleft #0 > }
  687. #if NAME_FULL
  688.     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
  689. #else
  690.     { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
  691. #endif NAME_FULL
  692.       nameptr #1 >
  693.     { namesleft #1 >
  694.         { ", " * t * }
  695.         { numnames #2 >
  696.         { "," * }
  697.         'skip$
  698.           if$
  699.           t "others" =
  700.         { " et~al." * }
  701.         { " and " * t * }
  702.           if$
  703.         }
  704.       if$
  705.     }
  706.     't
  707.       if$
  708.       nameptr #1 + 'nameptr :=
  709.       namesleft #1 - 'namesleft :=
  710.     }
  711.   while$
  712. }
  713.  
  714. FUNCTION {format.authors}
  715. { author empty$
  716.     { "" }
  717.     { author format.names }
  718.   if$
  719. }
  720.  
  721. FUNCTION {format.editors}
  722. { editor empty$
  723.     { "" }
  724.     { editor format.names
  725.       editor num.names$ #1 >
  726.     { ", editors" * }
  727.     { ", editor" * }
  728.       if$
  729.     }
  730.   if$
  731. }
  732.  
  733. % The format.title function is used for non-book-like titles.
  734. % For most styles we convert to lowercase (except for the very first letter,
  735. % and except for the first one after a colon (followed by whitespace)),
  736. % and hope the user has brace-surrounded words that need to stay capitilized;
  737. % for some styles, however, we leave it as it is in the database.
  738.  
  739. FUNCTION {format.title}
  740. { title empty$
  741.     { "" }
  742. #if ATIT_LOWER
  743.     { title "t" change.case$ }
  744. #else
  745.     'title
  746. #endif ATIT_LOWER
  747.   if$
  748. }
  749.  
  750. % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
  751. % constant glob_str_size, the maximum length of a global string variable.
  752. % Analogously, BibTeX sets the global integer variable entry.max$ to
  753. % ent_str_size, the maximum length of an entry string variable.
  754. % The style designer may change these if necessary (but this is unlikely)
  755.  
  756. % The n.dashify function makes each single `-' in a string a double `--'
  757. % if it's not already
  758. %
  759. % pseudoVAR: pageresult: STRING        (it's what's accumulated on the stack)
  760. %
  761. % n.dashify(s) ==
  762. %  BEGIN
  763. %    t := s
  764. %    pageresult := ""
  765. %    while (not empty$(t))
  766. %      do
  767. %        if (first character of t = "-")
  768. %          then
  769. %        if (next character isn't)
  770. %          then
  771. %            pageresult := pageresult * "--"
  772. %            t := t with the "-" removed
  773. %          else
  774. %            while (first character of t = "-")
  775. %              do
  776. %            pageresult := pageresult * "-"
  777. %            t := t with the "-" removed
  778. %              od
  779. %        fi
  780. %          else
  781. %        pageresult := pageresult * the first character
  782. %        t := t with the first character removed
  783. %        fi
  784. %      od
  785. %    return pageresult
  786. %  END
  787.  
  788. FUNCTION {n.dashify}
  789. { 't :=
  790.   ""
  791.     { t empty$ not }
  792.     { t #1 #1 substring$ "-" =
  793.     { t #1 #2 substring$ "--" = not
  794.         { "--" *
  795.           t #2 global.max$ substring$ 't :=
  796.         }
  797.         {   { t #1 #1 substring$ "-" = }
  798.         { "-" *
  799.           t #2 global.max$ substring$ 't :=
  800.         }
  801.           while$
  802.         }
  803.       if$
  804.     }
  805.     { t #1 #1 substring$ *
  806.       t #2 global.max$ substring$ 't :=
  807.     }
  808.       if$
  809.     }
  810.   while$
  811. }
  812.  
  813. % The format.date function is for the month and year, but we give a warning if
  814. % there's an empty year but the month is there, and we return the empty string
  815. % if they're both empty.
  816.  
  817. FUNCTION {format.date}
  818. { year empty$
  819.     { month empty$
  820.     { "" }
  821.     { "there's a month but no year in " cite$ * warning$
  822.       month
  823.     }
  824.       if$
  825.     }
  826.     { month empty$
  827.     'year
  828.     { month " " * year * }
  829.       if$
  830.     }
  831.   if$
  832. }
  833.  
  834. % The format.btitle is for formatting the title field when it is a book-like
  835. % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
  836.  
  837. FUNCTION {format.btitle}
  838. { title emphasize
  839. }
  840.  
  841. % For several functions we'll need to connect two strings with a
  842. % tie (~) if the second one isn't very long (fewer than 3 characters).
  843. % The tie.or.space.connect function does that.  It concatenates the two
  844. % strings on top of the stack, along with either a tie or space between
  845. % them, and puts this concatenation back onto the stack:
  846. %
  847. % tie.or.space.connect(str1,str2) ==
  848. %    BEGIN
  849. %    if text.length$(str2) < 3
  850. %      then return the concatenation of str1, "~", and str2
  851. %      else return the concatenation of str1, " ", and str2
  852. %    END
  853.  
  854. FUNCTION {tie.or.space.connect}
  855. { duplicate$ text.length$ #3 <
  856.     { "~" }
  857.     { " " }
  858.   if$
  859.   swap$ * *
  860. }
  861.  
  862. % The either.or.check function complains if both fields or an either-or pair
  863. % are nonempty.
  864. %
  865. % either.or.check(t,s) ==
  866. %  BEGIN
  867. %    if empty$(s) then
  868. %        warning$(can't use both " * t * " fields in " * cite$)
  869. %    fi
  870. %  END
  871.  
  872. FUNCTION {either.or.check}
  873. { empty$
  874.     'pop$
  875.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  876.   if$
  877. }
  878.  
  879. % The format.bvolume function is for formatting the volume and perhaps
  880. % series name of a multivolume work.  If both a volume and a series field
  881. % are there, we assume the series field is the title of the whole multivolume
  882. % work (the title field should be the title of the thing being referred to),
  883. % and we add an "of <series>".  This function is called in mid-sentence.
  884.  
  885. FUNCTION {format.bvolume}
  886. { volume empty$
  887.     { "" }
  888.     { "volume" volume tie.or.space.connect
  889.       series empty$
  890.     'skip$
  891.     { " of " * series emphasize * }
  892.       if$
  893.       "volume and number" number either.or.check
  894.     }
  895.   if$
  896. }
  897.  
  898. % The format.number.series function is for formatting the series name
  899. % and perhaps number of a work in a series.  This function is similar to
  900. % format.bvolume, although for this one the series must exist (and the
  901. % volume must not exist).  If the number field is empty we output either
  902. % the series field unchanged if it exists or else the null string.
  903. % If both the number and series fields are there we assume the series field
  904. % gives the name of the whole series (the title field should be the title
  905. % of the work being one referred to), and we add an "in <series>".
  906. % We capitilize Number when this function is used at the beginning of a block.
  907.  
  908. FUNCTION {format.number.series}
  909. { volume empty$
  910.     { number empty$
  911.     { series field.or.null }
  912.     { output.state mid.sentence =
  913.         { "number" }
  914.         { "Number" }
  915.       if$
  916.       number tie.or.space.connect
  917.       series empty$
  918.         { "there's a number but no series in " cite$ * warning$ }
  919.         { " in " * series * }
  920.       if$
  921.     }
  922.       if$
  923.     }
  924.     { "" }
  925.   if$
  926. }
  927.  
  928. % The format.edition function appends " edition" to the edition, if present.
  929. % We lowercase the edition (it should be something like "Third"), because
  930. % this doesn't start a sentence.
  931.  
  932. FUNCTION {format.edition}
  933. { edition empty$
  934.     { "" }
  935.     { output.state mid.sentence =
  936.     { edition "l" change.case$ " edition" * }
  937.     { edition "t" change.case$ " edition" * }
  938.       if$
  939.     }
  940.   if$
  941. }
  942.  
  943. % The format.pages function is used for formatting a page range in a book
  944. % (and in rare circumstances, an article).
  945. %
  946. % The multi.page.check function examines the page field for a "-" or "," or "+"
  947. % so that format.pages can use "page" instead of "pages" if none exists.
  948. % Note: global.max$ here means "take the rest of the string"
  949. %
  950. % VAR: multiresult: INTEGER    (actually, a boolean)
  951. %
  952. % multi.page.check(s) ==
  953. %  BEGIN
  954. %    t := s
  955. %    multiresult := false
  956. %    while ((not multiresult) and (not empty$(t)))
  957. %      do
  958. %        if (first character of t = "-" or "," or "+")
  959. %          then multiresult := true
  960. %          else t := t with the first character removed
  961. %        fi
  962. %      od
  963. %    return multiresult
  964. %  END
  965.  
  966. INTEGERS { multiresult }
  967.  
  968. FUNCTION {multi.page.check}
  969. { 't :=
  970.   #0 'multiresult :=
  971.     { multiresult not
  972.       t empty$ not
  973.       and
  974.     }
  975.     { t #1 #1 substring$
  976.       duplicate$ "-" =
  977.       swap$ duplicate$ "," =
  978.       swap$ "+" =
  979.       or or
  980.     { #1 'multiresult := }
  981.     { t #2 global.max$ substring$ 't := }
  982.       if$
  983.     }
  984.   while$
  985.   multiresult
  986. }
  987.  
  988. % This function doesn't begin a sentence so "pages" isn't capitalized.
  989. % Other functions that use this should keep that in mind.
  990.  
  991. FUNCTION {format.pages}
  992. { pages empty$
  993.     { "" }
  994.     { pages multi.page.check
  995.     { "pages" pages n.dashify tie.or.space.connect }
  996.     { "page" pages tie.or.space.connect }
  997.       if$
  998.     }
  999.   if$
  1000. }
  1001.  
  1002. % The format.vol.num.pages function is for the volume, number, and page range
  1003. % of a journal article.  We use the format:  vol(number):pages, with some
  1004. % variations for empty fields.  This doesn't begin a sentence.
  1005.  
  1006. FUNCTION {format.vol.num.pages}
  1007. { volume field.or.null
  1008.   number empty$
  1009.     'skip$
  1010.     { "(" number * ")" * *
  1011.       volume empty$
  1012.     { "there's a number but no volume in " cite$ * warning$ }
  1013.     'skip$
  1014.       if$
  1015.     }
  1016.   if$
  1017.   pages empty$
  1018.     'skip$
  1019.     { duplicate$ empty$
  1020.     { pop$ format.pages }
  1021.     { ":" * pages n.dashify * }
  1022.       if$
  1023.     }
  1024.   if$
  1025. }
  1026.  
  1027.  
  1028. % The format.chapter.pages, if the chapter is present, puts whatever is in the
  1029. % type field (or else "chapter" if type is empty) in front of a chapter number.
  1030. % It then appends the pages, if present.  This doesn't begin a sentence.
  1031.  
  1032. FUNCTION {format.chapter.pages}
  1033. { chapter empty$
  1034.     'format.pages
  1035.     { type empty$
  1036.     { "chapter" }
  1037.     { type "l" change.case$ }
  1038.       if$
  1039.       chapter tie.or.space.connect
  1040.       pages empty$
  1041.     'skip$
  1042.     { ", " * format.pages * }
  1043.       if$
  1044.     }
  1045.   if$
  1046. }
  1047.  
  1048. % The format.in.ed.booktitle function is used for starting out a sentence
  1049. % that begins "In <booktitle>", putting an editor before the title if one
  1050. % exists.
  1051.  
  1052. FUNCTION {format.in.ed.booktitle}
  1053. { booktitle empty$
  1054.     { "" }
  1055.     { editor empty$
  1056.     { "In " booktitle emphasize * }
  1057.     { "In " format.editors * ", " * booktitle emphasize * }
  1058.       if$
  1059.     }
  1060.   if$
  1061. }
  1062.  
  1063. % The function empty.misc.check complains if all six fields are empty, and
  1064. % if there's been no sorting or alphabetic-label complaint.
  1065.  
  1066. FUNCTION {empty.misc.check}
  1067. { author empty$ title empty$ howpublished empty$
  1068.   month empty$ year empty$ note empty$
  1069.   and and and and and
  1070. #if SORTED
  1071.   key empty$ not and
  1072. #else !SORTED
  1073. #if LAB_ALPH
  1074.   key empty$ not and
  1075. #endif LAB_ALPH
  1076. #endif SORTED
  1077.     { "all relevant fields are empty in " cite$ * warning$ }
  1078.     'skip$
  1079.   if$
  1080. }
  1081.  
  1082. % The function format.thesis.type returns either the (case-changed) type field,
  1083. % if it is defined, or else the default string already on the stack
  1084. % (like "Master's thesis" or "PhD thesis").
  1085.  
  1086. FUNCTION {format.thesis.type}
  1087. { type empty$
  1088.     'skip$
  1089.     { pop$
  1090.       type "t" change.case$
  1091.     }
  1092.   if$
  1093. }
  1094.  
  1095. % The function format.tr.number makes a string starting with "Technical Report"
  1096. % (or type, if that field is defined), followed by the number if there is one;
  1097. % it returns the starting part (with a case change) even if there is no number.
  1098. % This is used at the beginning of a sentence.
  1099.  
  1100. FUNCTION {format.tr.number}
  1101. { type empty$
  1102.     { "Technical Report" }
  1103.     'type
  1104.   if$
  1105.   number empty$
  1106.     { "t" change.case$ }
  1107.     { number tie.or.space.connect }
  1108.   if$
  1109. }
  1110.  
  1111. % Now come the cross-referencing functions (these are invoked because
  1112. % one entry in the database file(s) cross-references another, by giving
  1113. % the other entry's database key in a `crossref' field).  This feature
  1114. % allows one or more titled things that are part of a larger titled
  1115. % thing to cross-reference the larger thing.  These styles allow for
  1116. % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
  1117. % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
  1118. % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
  1119. % Each of these is explained in more detail later.
  1120. %
  1121. % An ARTICLE entry type may cross reference another ARTICLE (this is
  1122. % intended for when an entire journal is devoted to a single topic---
  1123. % but since there is no JOURNAL entry type, the journal, too, should be
  1124. % classified as an ARTICLE but without the author and title fields).
  1125. % This will result in two warning messages for the journal's entry
  1126. % if it's included in the reference list, but such is life.
  1127. %
  1128. % format.article.crossref ==
  1129. %  BEGIN
  1130. %    if empty$(key) then
  1131. %        if empty$(journal) then
  1132. %        warning$("need key or journal for " * cite$ *
  1133. %                        " to crossref " * crossref)
  1134. %        return(" \cite{" * crossref * "}")
  1135. %        else
  1136. %        return("In " * emphazise.correct (journal) *
  1137. %                        " \cite{" * crossref * "}")
  1138. %        fi
  1139. %    else
  1140. %        return("In " * key * " \cite{" * crossref * "}")
  1141. %    fi
  1142. %  END
  1143. %
  1144. % The other cross-referencing functions are similar, so no "comment version"
  1145. % will be given for them.
  1146.  
  1147. FUNCTION {format.article.crossref}
  1148. { key empty$
  1149.     { journal empty$
  1150.     { "need key or journal for " cite$ * " to crossref " * crossref *
  1151.       warning$
  1152.       ""
  1153.     }
  1154.     { "In {\em " journal * "\/}" * }
  1155.       if$
  1156.     }
  1157.     { "In " key * }
  1158.   if$
  1159.   " \cite{" * crossref * "}" *
  1160. }
  1161.  
  1162. % We use just the last names of editors for a cross reference: either
  1163. % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
  1164. % whether there are one, or two, or more than two editors.
  1165.  
  1166. FUNCTION {format.crossref.editor}
  1167. { editor #1 "{vv~}{ll}" format.name$
  1168.   editor num.names$ duplicate$
  1169.   #2 >
  1170.     { pop$ " et~al." * }
  1171.     { #2 <
  1172.     'skip$
  1173.     { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1174.         { " et~al." * }
  1175.         { " and " * editor #2 "{vv~}{ll}" format.name$ * }
  1176.       if$
  1177.     }
  1178.       if$
  1179.     }
  1180.   if$
  1181. }
  1182.  
  1183. % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
  1184. % multivolume work) may cross reference another BOOK (the entire multivolume).
  1185. % Usually there will be an editor, in which case we use that to construct the
  1186. % cross reference; otherwise we use a nonempty key field or else the series
  1187. % field (since the series gives the title of the multivolume work).
  1188.  
  1189. FUNCTION {format.book.crossref}
  1190. { volume empty$
  1191.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  1192.       "In "
  1193.     }
  1194.     { "Volume" volume tie.or.space.connect
  1195.       " of " *
  1196.     }
  1197.   if$
  1198.   editor empty$
  1199.   editor field.or.null author field.or.null =
  1200.   or
  1201.     { key empty$
  1202.     { series empty$
  1203.         { "need editor, key, or series for " cite$ * " to crossref " *
  1204.           crossref * warning$
  1205.           "" *
  1206.         }
  1207.         { "{\em " * series * "\/}" * }
  1208.       if$
  1209.     }
  1210.     { key * }
  1211.       if$
  1212.     }
  1213.     { format.crossref.editor * }
  1214.   if$
  1215.   " \cite{" * crossref * "}" *
  1216. }
  1217.  
  1218. % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
  1219. % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
  1220. % Often there will be an editor, in which case we use that to construct
  1221. % the cross reference; otherwise we use a nonempty key field or else
  1222. % the booktitle field (which gives the cross-referenced work's title).
  1223.  
  1224. FUNCTION {format.incoll.inproc.crossref}
  1225. { editor empty$
  1226.   editor field.or.null author field.or.null =
  1227.   or
  1228.     { key empty$
  1229.     { booktitle empty$
  1230.         { "need editor, key, or booktitle for " cite$ * " to crossref " *
  1231.           crossref * warning$
  1232.           ""
  1233.         }
  1234.         { "In {\em " booktitle * "\/}" * }
  1235.       if$
  1236.     }
  1237.     { "In " key * }
  1238.       if$
  1239.     }
  1240.     { "In " format.crossref.editor * }
  1241.   if$
  1242.   " \cite{" * crossref * "}" *
  1243. }
  1244.  
  1245. % Now we define the type functions for all entry types that may appear
  1246. % in the .BIB file---e.g., functions like `article' and `book'.  These
  1247. % are the routines that actually generate the .BBL-file output for
  1248. % the entry.  These must all precede the READ command.  In addition, the
  1249. % style designer should have a function `default.type' for unknown types.
  1250. % Note: The fields (within each list) are listed in order of appearance,
  1251. % except as described for an `inbook' or a `proceedings'.
  1252. %
  1253. % The article function is for an article in a journal.  An article may
  1254. % CROSSREF another article.
  1255. %    Required fields: author, title, journal, year
  1256. %    Optional fields: volume, number, pages, month, note
  1257. %
  1258. % article ==
  1259. %  BEGIN
  1260. %    output.bibitem
  1261. %    output.check(format.authors,"author")
  1262. %    new.block
  1263. %    output.check(format.title,"title")
  1264. %    new.block
  1265. %    if missing$(crossref) then
  1266. %        output.check(emphasize(journal),"journal")
  1267. %        output(format.vol.num.pages)
  1268. %        output.check(format.date,"year")
  1269. %       else
  1270. %        output.nonnull(format.article.crossref)
  1271. %        output(format.pages)
  1272. %    fi
  1273. %    new.block
  1274. %    output(note)
  1275. %    fin.entry
  1276. %  END
  1277. %
  1278. % The book function is for a whole book.  A book may CROSSREF another book.
  1279. %    Required fields: author or editor, title, publisher, year
  1280. %    Optional fields: volume or number, series, address, edition, month,
  1281. %            note
  1282. %
  1283. % book ==
  1284. %  BEGIN
  1285. %    if empty$(author) then output.check(format.editors,"author and editor")
  1286. %    else    output.check(format.authors,"author")
  1287. %        if missing$(crossref) then
  1288. %            either.or.check("author and editor",editor)
  1289. %        fi
  1290. %    fi
  1291. %    new.block
  1292. %    output.check(format.btitle,"title")
  1293. %    if missing$(crossref) then
  1294. %        output(format.bvolume)
  1295. %        new.block
  1296. %        output(format.number.series)
  1297. %        new.sentence
  1298. %        output.check(publisher,"publisher")
  1299. %        output(address)
  1300. %       else
  1301. %        new.block
  1302. %        output.nonnull(format.book.crossref)
  1303. %    fi
  1304. %    output(format.edition)
  1305. %    output.check(format.date,"year")
  1306. %    new.block
  1307. %    output(note)
  1308. %    fin.entry
  1309. %  END
  1310. %
  1311. % The other entry functions are all quite similar, so no "comment version"
  1312. % will be given for them.
  1313.  
  1314. FUNCTION {article}
  1315. { output.bibitem
  1316.   format.authors "author" output.check
  1317.   new.block
  1318.   format.title "title" output.check
  1319.   new.block
  1320.   crossref missing$
  1321.     { journal emphasize "journal" output.check
  1322.       format.vol.num.pages output
  1323.       format.date "year" output.check
  1324.     }
  1325.     { format.article.crossref output.nonnull
  1326.       format.pages output
  1327.     }
  1328.   if$
  1329.   new.block
  1330.   note output
  1331.   fin.entry
  1332. }
  1333.  
  1334. FUNCTION {book}
  1335. { output.bibitem
  1336.   author empty$
  1337.     { format.editors "author and editor" output.check }
  1338.     { format.authors output.nonnull
  1339.       crossref missing$
  1340.     { "author and editor" editor either.or.check }
  1341.     'skip$
  1342.       if$
  1343.     }
  1344.   if$
  1345.   new.block
  1346.   format.btitle "title" output.check
  1347.   crossref missing$
  1348.     { format.bvolume output
  1349.       new.block
  1350.       format.number.series output
  1351.       new.sentence
  1352.       publisher "publisher" output.check
  1353.       address output
  1354.     }
  1355.     { new.block
  1356.       format.book.crossref output.nonnull
  1357.     }
  1358.   if$
  1359.   format.edition output
  1360.   format.date "year" output.check
  1361.   new.block
  1362.   note output
  1363.   fin.entry
  1364. }
  1365.  
  1366. % A booklet is a bound thing without a publisher or sponsoring institution.
  1367. %    Required: title
  1368. %    Optional: author, howpublished, address, month, year, note
  1369.  
  1370. FUNCTION {booklet}
  1371. { output.bibitem
  1372.   format.authors output
  1373.   new.block
  1374.   format.title "title" output.check
  1375.   howpublished address new.block.checkb
  1376.   howpublished output
  1377.   address output
  1378.   format.date output
  1379.   new.block
  1380.   note output
  1381.   fin.entry
  1382. }
  1383.  
  1384. % For the conference entry type, see inproceedings.
  1385.  
  1386. % An inbook is a piece of a book: either a chapter and/or a page range.
  1387. % It may CROSSREF a book.  If there's no volume field, the type field
  1388. % will come before number and series.
  1389. %    Required: author or editor, title, chapter and/or pages, publisher,year
  1390. %    Optional: volume or number, series, type, address, edition, month, note
  1391.  
  1392. FUNCTION {inbook}
  1393. { output.bibitem
  1394.   author empty$
  1395.     { format.editors "author and editor" output.check }
  1396.     { format.authors output.nonnull
  1397.       crossref missing$
  1398.     { "author and editor" editor either.or.check }
  1399.     'skip$
  1400.       if$
  1401.     }
  1402.   if$
  1403.   new.block
  1404.   format.btitle "title" output.check
  1405.   crossref missing$
  1406.     { format.bvolume output
  1407.       format.chapter.pages "chapter and pages" output.check
  1408.       new.block
  1409.       format.number.series output
  1410.       new.sentence
  1411.       publisher "publisher" output.check
  1412.       address output
  1413.     }
  1414.     { format.chapter.pages "chapter and pages" output.check
  1415.       new.block
  1416.       format.book.crossref output.nonnull
  1417.     }
  1418.   if$
  1419.   format.edition output
  1420.   format.date "year" output.check
  1421.   new.block
  1422.   note output
  1423.   fin.entry
  1424. }
  1425.  
  1426. % An incollection is like inbook, but where there is a separate title
  1427. % for the referenced thing (and perhaps an editor for the whole).
  1428. % An incollection may CROSSREF a book.
  1429. %    Required: author, title, booktitle, publisher, year
  1430. %    Optional: editor, volume or number, series, type, chapter, pages,
  1431. %            address, edition, month, note
  1432.  
  1433. FUNCTION {incollection}
  1434. { output.bibitem
  1435.   format.authors "author" output.check
  1436.   new.block
  1437.   format.title "title" output.check
  1438.   new.block
  1439.   crossref missing$
  1440.     { format.in.ed.booktitle "booktitle" output.check
  1441.       format.bvolume output
  1442.       format.number.series output
  1443.       format.chapter.pages output
  1444.       new.sentence
  1445.       publisher "publisher" output.check
  1446.       address output
  1447.       format.edition output
  1448.       format.date "year" output.check
  1449.     }
  1450.     { format.incoll.inproc.crossref output.nonnull
  1451.       format.chapter.pages output
  1452.     }
  1453.   if$
  1454.   new.block
  1455.   note output
  1456.   fin.entry
  1457. }
  1458.  
  1459. % An inproceedings is an article in a conference proceedings, and it may
  1460. % CROSSREF a proceedings.  If there's no address field, the month (& year)
  1461. % will appear just before note.
  1462. %    Required: author, title, booktitle, year
  1463. %    Optional: editor, volume or number, series, pages, address, month,
  1464. %            organization, publisher, note
  1465.  
  1466. FUNCTION {inproceedings}
  1467. { output.bibitem
  1468.   format.authors "author" output.check
  1469.   new.block
  1470.   format.title "title" output.check
  1471.   new.block
  1472.   crossref missing$
  1473.     { format.in.ed.booktitle "booktitle" output.check
  1474.       format.bvolume output
  1475.       format.number.series output
  1476.       format.pages output
  1477.       address empty$
  1478.     { organization publisher new.sentence.checkb
  1479.       organization output
  1480.       publisher output
  1481.       format.date "year" output.check
  1482.     }
  1483.     { address output.nonnull
  1484.       format.date "year" output.check
  1485.       new.sentence
  1486.       organization output
  1487.       publisher output
  1488.     }
  1489.       if$
  1490.     }
  1491.     { format.incoll.inproc.crossref output.nonnull
  1492.       format.pages output
  1493.     }
  1494.   if$
  1495.   new.block
  1496.   note output
  1497.   fin.entry
  1498. }
  1499.  
  1500. % The conference function is included for Scribe compatibility.
  1501.  
  1502. FUNCTION {conference} { inproceedings }
  1503.  
  1504. % A manual is technical documentation.
  1505. %    Required: title
  1506. %    Optional: author, organization, address, edition, month, year, note
  1507.  
  1508. FUNCTION {manual}
  1509. { output.bibitem
  1510.   author empty$
  1511.     { organization empty$
  1512.     'skip$
  1513.     { organization output.nonnull
  1514.       address output
  1515.     }
  1516.       if$
  1517.     }
  1518.     { format.authors output.nonnull }
  1519.   if$
  1520.   new.block
  1521.   format.btitle "title" output.check
  1522.   author empty$
  1523.     { organization empty$
  1524.     { address new.block.checka
  1525.       address output
  1526.     }
  1527.     'skip$
  1528.       if$
  1529.     }
  1530.     { organization address new.block.checkb
  1531.       organization output
  1532.       address output
  1533.     }
  1534.   if$
  1535.   format.edition output
  1536.   format.date output
  1537.   new.block
  1538.   note output
  1539.   fin.entry
  1540. }
  1541.  
  1542. % A mastersthesis is a Master's thesis.
  1543. %    Required: author, title, school, year
  1544. %    Optional: type, address, month, note
  1545.  
  1546. FUNCTION {mastersthesis}
  1547. { output.bibitem
  1548.   format.authors "author" output.check
  1549.   new.block
  1550.   format.title "title" output.check
  1551.   new.block
  1552.   "Master's thesis" format.thesis.type output.nonnull
  1553.   school "school" output.check
  1554.   address output
  1555.   format.date "year" output.check
  1556.   new.block
  1557.   note output
  1558.   fin.entry
  1559. }
  1560.  
  1561. % A misc is something that doesn't fit elsewhere.
  1562. %    Required: at least one of the `optional' fields
  1563. %    Optional: author, title, howpublished, month, year, note
  1564.  
  1565. FUNCTION {misc}
  1566. { output.bibitem
  1567.   format.authors output
  1568.   title howpublished new.block.checkb
  1569.   format.title output
  1570.   howpublished new.block.checka
  1571.   howpublished output
  1572.   format.date output
  1573.   new.block
  1574.   note output
  1575.   fin.entry
  1576.   empty.misc.check
  1577. }
  1578.  
  1579. % A phdthesis is like a mastersthesis.
  1580. %    Required: author, title, school, year
  1581. %    Optional: type, address, month, note
  1582.  
  1583. FUNCTION {phdthesis}
  1584. { output.bibitem
  1585.   format.authors "author" output.check
  1586.   new.block
  1587.   format.btitle "title" output.check
  1588.   new.block
  1589.   "PhD thesis" format.thesis.type output.nonnull
  1590.   school "school" output.check
  1591.   address output
  1592.   format.date "year" output.check
  1593.   new.block
  1594.   note output
  1595.   fin.entry
  1596. }
  1597.  
  1598. % A proceedings is a conference proceedings.
  1599. % If there is an organization but no editor field, the organization will
  1600. % appear as the first optional field (we try to make the first block nonempty);
  1601. % if there's no address field, the month (& year) will appear just before note.
  1602. %    Required: title, year
  1603. %    Optional: editor, volume or number, series, address, month,
  1604. %            organization, publisher, note
  1605.  
  1606. FUNCTION {proceedings}
  1607. { output.bibitem
  1608.   editor empty$
  1609.     { organization output }
  1610.     { format.editors output.nonnull }
  1611.   if$
  1612.   new.block
  1613.   format.btitle "title" output.check
  1614.   format.bvolume output
  1615.   format.number.series output
  1616.   address empty$
  1617.     { editor empty$
  1618.     { publisher new.sentence.checka }
  1619.     { organization publisher new.sentence.checkb
  1620.       organization output
  1621.     }
  1622.       if$
  1623.       publisher output
  1624.       format.date "year" output.check
  1625.     }
  1626.     { address output.nonnull
  1627.       format.date "year" output.check
  1628.       new.sentence
  1629.       editor empty$
  1630.     'skip$
  1631.     { organization output }
  1632.       if$
  1633.       publisher output
  1634.     }
  1635.   if$
  1636.   new.block
  1637.   note output
  1638.   fin.entry
  1639. }
  1640.  
  1641. % A techreport is a technical report.
  1642. %    Required: author, title, institution, year
  1643. %    Optional: type, number, address, month, note
  1644.  
  1645. FUNCTION {techreport}
  1646. { output.bibitem
  1647.   format.authors "author" output.check
  1648.   new.block
  1649.   format.title "title" output.check
  1650.   new.block
  1651.   format.tr.number output.nonnull
  1652.   institution "institution" output.check
  1653.   address output
  1654.   format.date "year" output.check
  1655.   new.block
  1656.   note output
  1657.   fin.entry
  1658. }
  1659.  
  1660. % An unpublished is something that hasn't been published.
  1661. %    Required: author, title, note
  1662. %    Optional: month, year
  1663.  
  1664. FUNCTION {unpublished}
  1665. { output.bibitem
  1666.   format.authors "author" output.check
  1667.   new.block
  1668.   format.title "title" output.check
  1669.   new.block
  1670.   note "note" output.check
  1671.   format.date output
  1672.   fin.entry
  1673. }
  1674.  
  1675. % We use entry type `misc' for an unknown type; BibTeX gives a warning.
  1676.  
  1677. FUNCTION {default.type} { misc }
  1678.  
  1679. % Here are macros for common things that may vary from style to style.
  1680. % Users are encouraged to use these macros.
  1681. %
  1682. % Months are either written out in full or abbreviated
  1683.  
  1684. #if MONTH_FULL
  1685.  
  1686. MACRO {jan} {"January"}
  1687.  
  1688. MACRO {feb} {"February"}
  1689.  
  1690. MACRO {mar} {"March"}
  1691.  
  1692. MACRO {apr} {"April"}
  1693.  
  1694. MACRO {may} {"May"}
  1695.  
  1696. MACRO {jun} {"June"}
  1697.  
  1698. MACRO {jul} {"July"}
  1699.  
  1700. MACRO {aug} {"August"}
  1701.  
  1702. MACRO {sep} {"September"}
  1703.  
  1704. MACRO {oct} {"October"}
  1705.  
  1706. MACRO {nov} {"November"}
  1707.  
  1708. MACRO {dec} {"December"}
  1709.  
  1710. #else !MONTH_FULL
  1711.  
  1712. MACRO {jan} {"Jan."}
  1713.  
  1714. MACRO {feb} {"Feb."}
  1715.  
  1716. MACRO {mar} {"Mar."}
  1717.  
  1718. MACRO {apr} {"Apr."}
  1719.  
  1720. MACRO {may} {"May"}
  1721.  
  1722. MACRO {jun} {"June"}
  1723.  
  1724. MACRO {jul} {"July"}
  1725.  
  1726. MACRO {aug} {"Aug."}
  1727.  
  1728. MACRO {sep} {"Sept."}
  1729.  
  1730. MACRO {oct} {"Oct."}
  1731.  
  1732. MACRO {nov} {"Nov."}
  1733.  
  1734. MACRO {dec} {"Dec."}
  1735.  
  1736. #endif MONTH_FULL
  1737.  
  1738. % Journals are either written out in full or abbreviated;
  1739. % the abbreviations are like those found in ACM publications.
  1740. %
  1741. % To get a completely different set of abbreviations, it may be best to make
  1742. % a separate .bib file with nothing but those abbreviations; users could then
  1743. % include that file name as the first argument to the \bibliography command
  1744.  
  1745. #if JOUR_FULL
  1746.  
  1747. MACRO {acmcs} {"ACM Computing Surveys"}
  1748.  
  1749. MACRO {acta} {"Acta Informatica"}
  1750.  
  1751. MACRO {cacm} {"Communications of the ACM"}
  1752.  
  1753. MACRO {ibmjrd} {"IBM Journal of Research and Development"}
  1754.  
  1755. MACRO {ibmsj} {"IBM Systems Journal"}
  1756.  
  1757. MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
  1758.  
  1759. MACRO {ieeetc} {"IEEE Transactions on Computers"}
  1760.  
  1761. MACRO {ieeetcad}
  1762.  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
  1763.  
  1764. MACRO {ipl} {"Information Processing Letters"}
  1765.  
  1766. MACRO {jacm} {"Journal of the ACM"}
  1767.  
  1768. MACRO {jcss} {"Journal of Computer and System Sciences"}
  1769.  
  1770. MACRO {scp} {"Science of Computer Programming"}
  1771.  
  1772. MACRO {sicomp} {"SIAM Journal on Computing"}
  1773.  
  1774. MACRO {tocs} {"ACM Transactions on Computer Systems"}
  1775.  
  1776. MACRO {tods} {"ACM Transactions on Database Systems"}
  1777.  
  1778. MACRO {tog} {"ACM Transactions on Graphics"}
  1779.  
  1780. MACRO {toms} {"ACM Transactions on Mathematical Software"}
  1781.  
  1782. MACRO {toois} {"ACM Transactions on Office Information Systems"}
  1783.  
  1784. MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
  1785.  
  1786. MACRO {tcs} {"Theoretical Computer Science"}
  1787.  
  1788. #else !JOUR_FULL
  1789.  
  1790. MACRO {acmcs} {"ACM Comput. Surv."}
  1791.  
  1792. MACRO {acta} {"Acta Inf."}
  1793.  
  1794. MACRO {cacm} {"Commun. ACM"}
  1795.  
  1796. MACRO {ibmjrd} {"IBM J. Res. Dev."}
  1797.  
  1798. MACRO {ibmsj} {"IBM Syst.~J."}
  1799.  
  1800. MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
  1801.  
  1802. MACRO {ieeetc} {"IEEE Trans. Comput."}
  1803.  
  1804. MACRO {ieeetcad}
  1805.  {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
  1806.  
  1807. MACRO {ipl} {"Inf. Process. Lett."}
  1808.  
  1809. MACRO {jacm} {"J.~ACM"}
  1810.  
  1811. MACRO {jcss} {"J.~Comput. Syst. Sci."}
  1812.  
  1813. MACRO {scp} {"Sci. Comput. Programming"}
  1814.  
  1815. MACRO {sicomp} {"SIAM J. Comput."}
  1816.  
  1817. MACRO {tocs} {"ACM Trans. Comput. Syst."}
  1818.  
  1819. MACRO {tods} {"ACM Trans. Database Syst."}
  1820.  
  1821. MACRO {tog} {"ACM Trans. Gr."}
  1822.  
  1823. MACRO {toms} {"ACM Trans. Math. Softw."}
  1824.  
  1825. MACRO {toois} {"ACM Trans. Office Inf. Syst."}
  1826.  
  1827. MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
  1828.  
  1829. MACRO {tcs} {"Theoretical Comput. Sci."}
  1830.  
  1831. #endif JOUR_FULL
  1832.  
  1833. % Now we read in the .BIB entries.
  1834.  
  1835. READ
  1836.  
  1837. % The sortify function converts to lower case after purify$ing; it's
  1838. % used in sorting and in computing alphabetic labels after sorting
  1839. %
  1840. % The chop.word(w,len,s) function returns either s or, if the first len
  1841. % letters of s equals w (this comparison is done in the third line of the
  1842. % function's definition), it returns that part of s after w.
  1843.  
  1844. #if SORTED
  1845.  
  1846. FUNCTION {sortify}
  1847. { purify$
  1848.   "l" change.case$
  1849. }
  1850.  
  1851. INTEGERS { len }
  1852.  
  1853. FUNCTION {chop.word}
  1854. { 's :=
  1855.   'len :=
  1856.   s #1 len substring$ =
  1857.     { s len #1 + global.max$ substring$ }
  1858.     's
  1859.   if$
  1860. }
  1861.  
  1862. #else !SORTED
  1863. #if LAB_ALPH
  1864.  
  1865. % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
  1866.  
  1867. INTEGERS { len }
  1868.  
  1869. FUNCTION {chop.word}
  1870. { 's :=
  1871.   'len :=
  1872.   s #1 len substring$ =
  1873.     { s len #1 + global.max$ substring$ }
  1874.     's
  1875.   if$
  1876. }
  1877.  
  1878. #endif LAB_ALPH
  1879. #endif SORTED
  1880.  
  1881. % This long comment applies only to alphabetic labels
  1882. %
  1883. % The format.lab.names function makes a short label by using the initials of
  1884. % the von and Last parts of the names (but if there are more than four names,
  1885. % (i.e., people) it truncates after three and adds a superscripted "+";
  1886. % it also adds such a "+" if the last of multiple authors is "others").
  1887. % If there is only one name, and its von and Last parts combined have just
  1888. % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
  1889. % we take the first three letters of the last name.  The boolean
  1890. % et.al.char.used tells whether we've used a superscripted "+", so that we
  1891. % know whether to include a LaTeX macro for it.
  1892. %
  1893. % format.lab.names(s) ==
  1894. %  BEGIN
  1895. %    numnames := num.names$(s)
  1896. %    if numnames > 1 then
  1897. %        if numnames > 4 then
  1898. %        namesleft := 3
  1899. %        else
  1900. %        namesleft := numnames
  1901. %        nameptr := 1
  1902. %        nameresult := ""
  1903. %        while namesleft > 0
  1904. %          do
  1905. %        if (name_ptr = numnames) and
  1906. %             format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
  1907. %           then nameresult := nameresult * "{\etalchar{+}}"
  1908. %            et.al.char.used := true
  1909. %           else nameresult := nameresult *
  1910. %                format.name$(s, nameptr, "{v{}}{l{}}")
  1911. %        nameptr := nameptr + 1
  1912. %        namesleft := namesleft - 1
  1913. %          od
  1914. %        if numnames > 4 then
  1915. %        nameresult := nameresult * "{\etalchar{+}}"
  1916. %        et.al.char.used := true
  1917. %    else
  1918. %        t := format.name$(s, 1, "{v{}}{l{}}")
  1919. %        if text.length$(t) < 2 then    % there's just one name-token
  1920. %        nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
  1921. %        else
  1922. %        nameresult := t
  1923. %        fi
  1924. %    fi
  1925. %    return nameresult
  1926. %  END
  1927. %
  1928. % Exactly what fields we look at in constructing the primary part of the label
  1929. % depends on the entry type; this selectivity (as opposed to, say, always
  1930. % looking at author, then editor, then key) helps ensure that "ignored" fields,
  1931. % as described in the LaTeX book, really are ignored.  Note that MISC is part
  1932. % of the deepest `else' clause in the nested part of calc.label; thus, any
  1933. % unrecognized entry type in the database is handled correctly.
  1934. %
  1935. % There is one auxiliary function for each of the four different sequences of
  1936. % fields we use.  The first of these functions looks at the author field, and
  1937. % then, if necessary, the key field.  The other three functions, which might
  1938. % look at two fields and the key field, are similar, except that the key field
  1939. % takes precedence over the organization field (for labels---not for sorting).
  1940. %
  1941. % The calc.label function calculates the preliminary label of an entry, which
  1942. % is formed by taking three letters of information from the author or editor or
  1943. % key or organization field (depending on the entry type and on what's empty,
  1944. % but ignoring a leading "The " in the organization), and appending the last
  1945. % two characters (digits) of the year. It is an error if the appropriate fields
  1946. % among author, editor, organization, and key are missing, and we use
  1947. % the first three letters of the cite$ in desperation when this happens.
  1948. % The resulting label has the year part, but not the name part, purify$ed
  1949. % (purify$ing the year allows some sorting shenanigans by the user).
  1950. %
  1951. % This function also calculates the version of the label to be used in sorting.
  1952. %
  1953. % The final label may need a trailing 'a', 'b', etc., to distinguish it from
  1954. % otherwise identical labels, but we can't calculated those "extra.label"s
  1955. % until after sorting.
  1956. %
  1957. % calc.label ==
  1958. %  BEGIN
  1959. %    if type$ = "book" or "inbook" then
  1960. %        author.editor.key.label
  1961. %    else if type$ = "proceedings" then
  1962. %        editor.key.organization.label
  1963. %    else if type$ = "manual" then
  1964. %        author.key.organization.label
  1965. %    else
  1966. %        author.key.label
  1967. %    fi fi fi
  1968. %    label := label * substring$(purify$(field.or.null(year)), -1, 2)
  1969. %        % assuming we will also sort, we calculate a sort.label
  1970. %    sort.label := sortify(label), but use the last four, not two, digits
  1971. %  END
  1972.  
  1973. #if LAB_ALPH
  1974.  
  1975. INTEGERS { et.al.char.used }
  1976.  
  1977. FUNCTION {initialize.et.al.char.used}
  1978. { #0 'et.al.char.used :=
  1979. }
  1980.  
  1981. EXECUTE {initialize.et.al.char.used}
  1982.  
  1983. FUNCTION {format.lab.names}
  1984. { 's :=
  1985.   s num.names$ 'numnames :=
  1986.   numnames #1 >
  1987.     { numnames #4 >
  1988.     { #3 'namesleft := }
  1989.     { numnames 'namesleft := }
  1990.       if$
  1991.       #1 'nameptr :=
  1992.       ""
  1993.     { namesleft #0 > }
  1994.     { nameptr numnames =
  1995.         { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  1996.         { "{\etalchar{+}}" *
  1997.           #1 'et.al.char.used :=
  1998.         }
  1999.         { s nameptr "{v{}}{l{}}" format.name$ * }
  2000.           if$
  2001.         }
  2002.         { s nameptr "{v{}}{l{}}" format.name$ * }
  2003.       if$
  2004.       nameptr #1 + 'nameptr :=
  2005.       namesleft #1 - 'namesleft :=
  2006.     }
  2007.       while$
  2008.       numnames #4 >
  2009.     { "{\etalchar{+}}" *
  2010.       #1 'et.al.char.used :=
  2011.     }
  2012.     'skip$
  2013.       if$
  2014.     }
  2015.     { s #1 "{v{}}{l{}}" format.name$
  2016.       duplicate$ text.length$ #2 <
  2017.     { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
  2018.     'skip$
  2019.       if$
  2020.     }
  2021.   if$
  2022. }
  2023.  
  2024. FUNCTION {author.key.label}
  2025. { author empty$
  2026.     { key empty$
  2027. #if SORTED
  2028.     { cite$ #1 #3 substring$ }
  2029. #else !SORTED        % need warning here because we won't give it later
  2030.     { "for label, need author or key in " cite$ * warning$
  2031.       cite$ #1 #3 substring$
  2032.     }
  2033. #endif SORTED
  2034.     { key #3 text.prefix$ }
  2035.       if$
  2036.     }
  2037.     { author format.lab.names }
  2038.   if$
  2039. }
  2040.  
  2041. FUNCTION {author.editor.key.label}
  2042. { author empty$
  2043.     { editor empty$
  2044.     { key empty$
  2045. #if SORTED
  2046.         { cite$ #1 #3 substring$ }
  2047. #else !SORTED        % need warning here because we won't give it later
  2048.         { "for label, need author, editor, or key in " cite$ * warning$
  2049.           cite$ #1 #3 substring$
  2050.         }
  2051. #endif SORTED
  2052.         { key #3 text.prefix$ }
  2053.       if$
  2054.     }
  2055.     { editor format.lab.names }
  2056.       if$
  2057.     }
  2058.     { author format.lab.names }
  2059.   if$
  2060. }
  2061.  
  2062. FUNCTION {author.key.organization.label}
  2063. { author empty$
  2064.     { key empty$
  2065.     { organization empty$
  2066. #if SORTED
  2067.         { cite$ #1 #3 substring$ }
  2068. #else !SORTED        % need warning here because we won't give it later
  2069.         { "for label, need author, key, or organization in " cite$ *
  2070.                                 warning$
  2071.           cite$ #1 #3 substring$
  2072.         }
  2073. #endif SORTED
  2074.         { "The " #4 organization chop.word #3 text.prefix$ }
  2075.       if$
  2076.     }
  2077.     { key #3 text.prefix$ }
  2078.       if$
  2079.     }
  2080.     { author format.lab.names }
  2081.   if$
  2082. }
  2083.  
  2084. FUNCTION {editor.key.organization.label}
  2085. { editor empty$
  2086.     { key empty$
  2087.     { organization empty$
  2088. #if SORTED
  2089.         { cite$ #1 #3 substring$ }
  2090. #else !SORTED        % need warning here because we won't give it later
  2091.         { "for label, need editor, key, or organization in " cite$ *
  2092.                                 warning$
  2093.           cite$ #1 #3 substring$
  2094.         }
  2095. #endif SORTED
  2096.         { "The " #4 organization chop.word #3 text.prefix$ }
  2097.       if$
  2098.     }
  2099.     { key #3 text.prefix$ }
  2100.       if$
  2101.     }
  2102.     { editor format.lab.names }
  2103.   if$
  2104. }
  2105.  
  2106. FUNCTION {calc.label}
  2107. { type$ "book" =
  2108.   type$ "inbook" =
  2109.   or
  2110.     'author.editor.key.label
  2111.     { type$ "proceedings" =
  2112.     'editor.key.organization.label
  2113.     { type$ "manual" =
  2114.         'author.key.organization.label
  2115.         'author.key.label
  2116.       if$
  2117.     }
  2118.       if$
  2119.     }
  2120.   if$
  2121.   duplicate$
  2122.   year field.or.null purify$ #-1 #2 substring$
  2123.   *
  2124.   'label :=
  2125.   year field.or.null purify$ #-1 #4 substring$
  2126.   *
  2127.   sortify 'sort.label :=
  2128. }
  2129.  
  2130. % It doesn't seem like a particularly good idea to use an order-of-citation
  2131. % reference list when using alphabetic labels, but we need to have a
  2132. % special pass to calculate labels when this happens.
  2133.  
  2134. #if !SORTED
  2135.  
  2136. ITERATE {calc.label}
  2137.  
  2138. #endif !SORTED
  2139.  
  2140. #endif LAB_ALPH
  2141.  
  2142. % When sorting, we compute the sortkey by executing "presort" on each entry.
  2143. % The presort key contains a number of "sortify"ed strings, concatenated
  2144. % with multiple blanks between them.  This makes things like "brinch  per"
  2145. % come before "brinch hansen  per".
  2146. %
  2147. % The fields used here are: the sort.label for alphabetic labels (as set by
  2148. % calc.label), followed by the author names (or editor names or organization
  2149. % (with a leading "The " removed) or key field, depending on entry type and on
  2150. % what's empty), followed by year, followed by the first bit of the title
  2151. % (chopping off a leading "The ", "A ", or "An ").
  2152. % Names are formatted: Von Last First Junior.
  2153. % The names within a part will be separated by a single blank
  2154. % (such as "brinch hansen"), two will separate the name parts themselves
  2155. % (except the von and last), three will separate the names,
  2156. % four will separate the names from year (and from label, if alphabetic),
  2157. % and four will separate year from title.
  2158. %
  2159. % The sort.format.names function takes an argument that should be in
  2160. % BibTeX name format, and returns a string containing "   "-separated
  2161. % names in the format described above.  The function is almost the same
  2162. % as format.names.
  2163.  
  2164. #if SORTED
  2165.  
  2166. FUNCTION {sort.format.names}
  2167. { 's :=
  2168.   #1 'nameptr :=
  2169.   ""
  2170.   s num.names$ 'numnames :=
  2171.   numnames 'namesleft :=
  2172.     { namesleft #0 > }
  2173.     { nameptr #1 >
  2174.     { "   " * }
  2175.     'skip$
  2176.       if$
  2177. #if NAME_FULL
  2178.       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
  2179. #else
  2180.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't :=
  2181. #endif NAME_FULL
  2182.       nameptr numnames = t "others" = and
  2183.     { "et al" * }
  2184.     { t sortify * }
  2185.       if$
  2186.       nameptr #1 + 'nameptr :=
  2187.       namesleft #1 - 'namesleft :=
  2188.     }
  2189.   while$
  2190. }
  2191.  
  2192. % The sort.format.title function returns the argument,
  2193. % but first any leading "A "'s, "An "'s, or "The "'s are removed.
  2194. % The chop.word function uses s, so we need another string variable, t
  2195.  
  2196. FUNCTION {sort.format.title}
  2197. { 't :=
  2198.   "A " #2
  2199.     "An " #3
  2200.       "The " #4 t chop.word
  2201.     chop.word
  2202.   chop.word
  2203.   sortify
  2204.   #1 global.max$ substring$
  2205. }
  2206.  
  2207. % The auxiliary functions here, for the presort function, are analogous to
  2208. % the ones for calc.label; the same comments apply, except that the
  2209. % organization field takes precedence here over the key field.  For sorting
  2210. % purposes, we still remove a leading "The " from the organization field.
  2211.  
  2212. FUNCTION {author.sort}
  2213. { author empty$
  2214.     { key empty$
  2215.     { "to sort, need author or key in " cite$ * warning$
  2216.       ""
  2217.     }
  2218.     { key sortify }
  2219.       if$
  2220.     }
  2221.     { author sort.format.names }
  2222.   if$
  2223. }
  2224.  
  2225. FUNCTION {author.editor.sort}
  2226. { author empty$
  2227.     { editor empty$
  2228.     { key empty$
  2229.         { "to sort, need author, editor, or key in " cite$ * warning$
  2230.           ""
  2231.         }
  2232.         { key sortify }
  2233.       if$
  2234.     }
  2235.     { editor sort.format.names }
  2236.       if$
  2237.     }
  2238.     { author sort.format.names }
  2239.   if$
  2240. }
  2241.  
  2242. FUNCTION {author.organization.sort}
  2243. { author empty$
  2244.     { organization empty$
  2245.     { key empty$
  2246.         { "to sort, need author, organization, or key in " cite$ * warning$
  2247.           ""
  2248.         }
  2249.         { key sortify }
  2250.       if$
  2251.     }
  2252.     { "The " #4 organization chop.word sortify }
  2253.       if$
  2254.     }
  2255.     { author sort.format.names }
  2256.   if$
  2257. }
  2258.  
  2259. FUNCTION {editor.organization.sort}
  2260. { editor empty$
  2261.     { organization empty$
  2262.     { key empty$
  2263.         { "to sort, need editor, organization, or key in " cite$ * warning$
  2264.           ""
  2265.         }
  2266.         { key sortify }
  2267.       if$
  2268.     }
  2269.     { "The " #4 organization chop.word sortify }
  2270.       if$
  2271.     }
  2272.     { editor sort.format.names }
  2273.   if$
  2274. }
  2275.  
  2276. % There is a limit, entry.max$, on the length of an entry string variable
  2277. % (which is what its sort.key$ is), so we take at most that many characters
  2278. % of the constructed key, and hope there aren't many references that match
  2279. % to that many characters!
  2280.  
  2281. FUNCTION {presort}
  2282. #if LAB_ALPH
  2283. { calc.label
  2284.   sort.label
  2285.   "    "
  2286.   *
  2287.   type$ "book" =
  2288. #else !LAB_ALPH
  2289. { type$ "book" =
  2290. #endif LAB_ALPH
  2291.   type$ "inbook" =
  2292.   or
  2293.     'author.editor.sort
  2294.     { type$ "proceedings" =
  2295.     'editor.organization.sort
  2296.     { type$ "manual" =
  2297.         'author.organization.sort
  2298.         'author.sort
  2299.       if$
  2300.     }
  2301.       if$
  2302.     }
  2303.   if$
  2304. #if LAB_ALPH
  2305.   *
  2306. #endif LAB_ALPH
  2307.   "    "
  2308.   *
  2309.   year field.or.null sortify
  2310.   *
  2311.   "    "
  2312.   *
  2313.   title field.or.null
  2314.   sort.format.title
  2315.   *
  2316.   #1 entry.max$ substring$
  2317.   'sort.key$ :=
  2318. }
  2319.  
  2320. ITERATE {presort}
  2321.  
  2322. % And now we can sort
  2323.  
  2324. SORT
  2325.  
  2326. #endif SORTED
  2327.  
  2328. % This long comment applies only to alphabetic labels, when sorted
  2329. %
  2330. % Now comes the final computation for alphabetic labels, putting in the 'a's
  2331. % and 'b's and so forth if required.  This involves two passes: a forward
  2332. % pass to put in the 'b's, 'c's and so on, and a backwards pass
  2333. % to put in the 'a's (we don't want to put in 'a's unless we know there
  2334. % are 'b's).
  2335. % We have to keep track of the longest (in width$ terms) label, for use
  2336. % by the "thebibliography" environment.
  2337. %
  2338. % VAR: longest.label, last.sort.label, next.extra: string
  2339. %      longest.label.width, last.extra.num: integer
  2340. %
  2341. % initialize.longest.label ==
  2342. %  BEGIN
  2343. %    longest.label := ""
  2344. %    last.sort.label := int.to.chr$(0)
  2345. %    next.extra := ""
  2346. %    longest.label.width := 0
  2347. %    last.extra.num := 0
  2348. %  END
  2349. %
  2350. % forward.pass ==
  2351. %  BEGIN
  2352. %    if last.sort.label = sort.label then
  2353. %        last.extra.num := last.extra.num + 1
  2354. %        extra.label := int.to.chr$(last.extra.num)
  2355. %    else
  2356. %        last.extra.num := chr.to.int$("a")
  2357. %        extra.label := ""
  2358. %        last.sort.label := sort.label
  2359. %    fi
  2360. %  END
  2361. %
  2362. % reverse.pass ==
  2363. %  BEGIN
  2364. %    if next.extra = "b" then
  2365. %        extra.label := "a"
  2366. %    fi
  2367. %    label := label * extra.label
  2368. %    if width$(label) > longest.label.width then
  2369. %        longest.label := label
  2370. %        longest.label.width := width$(label)
  2371. %    fi
  2372. %    next.extra := extra.label
  2373. %  END
  2374.  
  2375. #if LAB_ALPH
  2376.  
  2377. #if SORTED
  2378.  
  2379. STRINGS { longest.label last.sort.label next.extra }
  2380.  
  2381. INTEGERS { longest.label.width last.extra.num }
  2382.  
  2383. FUNCTION {initialize.longest.label}
  2384. { "" 'longest.label :=
  2385.   #0 int.to.chr$ 'last.sort.label :=
  2386.   "" 'next.extra :=
  2387.   #0 'longest.label.width :=
  2388.   #0 'last.extra.num :=
  2389. }
  2390.  
  2391. FUNCTION {forward.pass}
  2392. { last.sort.label sort.label =
  2393.     { last.extra.num #1 + 'last.extra.num :=
  2394.       last.extra.num int.to.chr$ 'extra.label :=
  2395.     }
  2396.     { "a" chr.to.int$ 'last.extra.num :=
  2397.       "" 'extra.label :=
  2398.       sort.label 'last.sort.label :=
  2399.     }
  2400.   if$
  2401. }
  2402.  
  2403. FUNCTION {reverse.pass}
  2404. { next.extra "b" =
  2405.     { "a" 'extra.label := }
  2406.     'skip$
  2407.   if$
  2408.   label extra.label * 'label :=
  2409.   label width$ longest.label.width >
  2410.     { label 'longest.label :=
  2411.       label width$ 'longest.label.width :=
  2412.     }
  2413.     'skip$
  2414.   if$
  2415.   extra.label 'next.extra :=
  2416. }
  2417.  
  2418. EXECUTE {initialize.longest.label}
  2419.  
  2420. ITERATE {forward.pass}
  2421.  
  2422. REVERSE {reverse.pass}
  2423.  
  2424. #else !SORTED
  2425.  
  2426. % It still doesn't seem like a good idea to use an order-of-citation
  2427. % reference list when using alphabetic labels, but when this happens we
  2428. % must compute the longest label
  2429.  
  2430. STRINGS { longest.label }
  2431.  
  2432. INTEGERS { longest.label.width }
  2433.  
  2434. FUNCTION {initialize.longest.label}
  2435. { "" 'longest.label :=
  2436.   #0 'longest.label.width :=
  2437. }
  2438.  
  2439. FUNCTION {longest.label.pass}
  2440. { label width$ longest.label.width >
  2441.     { label 'longest.label :=
  2442.       label width$ 'longest.label.width :=
  2443.     }
  2444.     'skip$
  2445.   if$
  2446. }
  2447.  
  2448. EXECUTE {initialize.longest.label}
  2449.  
  2450. ITERATE {longest.label.pass}
  2451.  
  2452. #endif SORTED
  2453.  
  2454. #else !LAB_ALPH
  2455.  
  2456. % Now comes the computation for numeric labels.
  2457. % We use either the sorted order or original order.
  2458. % We still have to keep track of the longest (in width$ terms) label, for use
  2459. % by the "thebibliography" environment.
  2460.  
  2461. STRINGS { longest.label }
  2462.  
  2463. INTEGERS { number.label longest.label.width }
  2464.  
  2465. FUNCTION {initialize.longest.label}
  2466. { "" 'longest.label :=
  2467.   #1 'number.label :=
  2468.   #0 'longest.label.width :=
  2469. }
  2470.  
  2471. FUNCTION {longest.label.pass}
  2472. { number.label int.to.str$ 'label :=
  2473.   number.label #1 + 'number.label :=
  2474.   label width$ longest.label.width >
  2475.     { label 'longest.label :=
  2476.       label width$ 'longest.label.width :=
  2477.     }
  2478.     'skip$
  2479.   if$
  2480. }
  2481.  
  2482. EXECUTE {initialize.longest.label}
  2483.  
  2484. ITERATE {longest.label.pass}
  2485.  
  2486. #endif LAB_ALPH
  2487.  
  2488. % Now we're ready to start writing the .BBL file.
  2489. % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
  2490. % label; next comes stuff from the `preamble' command in the database files.
  2491. % Then we give an incantation containing the command
  2492. %     \begin{thebibliography}{...}
  2493. % where the `...' is the longest label.
  2494. %
  2495. % We also call init.state.consts, for use by the output routines.
  2496.  
  2497. FUNCTION {begin.bib}
  2498. #if LAB_ALPH
  2499. { et.al.char.used
  2500.     { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
  2501.     'skip$
  2502.   if$
  2503.   preamble$ empty$
  2504. #else !LAB_ALPH
  2505. { preamble$ empty$
  2506. #endif LAB_ALPH
  2507.     'skip$
  2508.     { preamble$ write$ newline$ }
  2509.   if$
  2510.   "\begin{thebibliography}{"  longest.label  * "}" * write$ newline$
  2511. }
  2512.  
  2513. EXECUTE {begin.bib}
  2514.  
  2515. EXECUTE {init.state.consts}
  2516.  
  2517. % Now we produce the output for all the entries
  2518.  
  2519. ITERATE {call.type$}
  2520.  
  2521. % Finally, we finish up by writing the `\end{thebibliography}' command.
  2522.  
  2523. FUNCTION {end.bib}
  2524. { newline$
  2525.   "\end{thebibliography}" write$ newline$
  2526. }
  2527.  
  2528. EXECUTE {end.bib}
  2529.